// class类
class Person {
    // 声明构造器当中属性的类型
    name: string;
    age: number;
    // 构造器
    constructor(name: string, age: number) {
        this.name = name;
        this.age = age;
    }
    // 原型对象上的方法：
    jump(x: string): string {
        return x + this.name
    }
    // class类 自身上的方法
    static run(y: number): number {
        return y
    }

}

let tom = new Person("tom", 22);
// 调用class类 原型上的方法
console.log(tom.jump("你们好好的！！"));
// 调用class类自身或者构造函数自身上的方法
console.log(Person.run(123456));
console.log(Person["run"]);


// 使用接口规定的数据类型
interface Anima {
    sound(str: string): string;
    weight(num: number): number;

}
interface Anima2 {
    name(str: string): string;

}
// 接口定义 class类的数据类型，一个类可以使用多个接口进行规定
class Cat implements Anima, Anima2 {
    sound(a: string): string {
        return a
    }
    weight(num: number): number {
        return num
    }
    name(nam: string): string {
        return nam
    }
}

let Kitty = new Cat();
console.log(Kitty);
console.log(Kitty.sound("1234321"));
console.log(Kitty.weight(123456));

// 接口继承
interface DogInp{
    sound(str:string):string
}
interface DogInc{
    number(num:number):number
}
// class Dog implements DogInp,DogInc{
//     sound(str: string): string {
//         return str
//     }
//     number(num:number):number{
//         return num
//     }
// }
// let liuchao = new Dog();
// console.log(liuchao);
// console.log(liuchao.sound("09876"));

interface NewIn extends DogInp,DogInc{

}
class Dog implements NewIn{
    sound(str:string):string{
        return str
    }
    number(num:number):number{
        return num
    }
}
let liuchao = new Dog();
console.log(liuchao.number(9527));
console.log(liuchao.sound("yuewgg"));

// class类的继承
class Students extends Person{
    sex:string;
    constructor(name:string,age:number,sex:string){
        super(name,age);
        this.sex=sex;
    }
    jump(h: string):string {
        return super.jump(h);
    }
}
let chaochao = new Students("chaochao",22,"nan");
console.log(chaochao.jump("喜爱美食"));

// 修饰符

class Book{
    public name:string; 
    private age:number;
    protected sex:string; 
    hobby:string;
    constructor(name:string,age:number,sex:string,hobby:string){
        this.name = name;
        this.age =age;
        this.sex = sex;
        this.hobby=hobby;
    }
    jumps():string{
        // 可在class内部访问
        console.log(this.name);
        console.log(this.age);
        console.log(this.sex);
        
        return this.name
        
        
    }
}
let wangs = new Book("liuming",12,"nv","打游戏");
console.log(wangs);
// console.log(wangs.name);
wangs.jumps()
// console.log(wangs.age(12));

// 
class Sunzhi extends Book{
    constructor(name:string,age:number,sex:string,hobby:string){
        super(name,age,sex,hobby);
    }
    test():void{
        console.log(this.sex);
        // console.log(this.age);
        console.log(this.name);
        console.log(this.hobby);
        
        
        
    }
}
let wen = new Sunzhi("海上世界",12,"女","玩游戏")
console.log(wen);
console.log(wen.test());
console.log(wen.hobby);





// 简写方式
class Liuchao{
    constructor(public name:string,public age:number){
        this.name=name;
        this.age=age;
    }

}
let liu = new Liuchao("超超",22);
console.log(liu);


// 存取器
class Persons{
    name:string="洋洋";
    hobby:string="玩游戏";
    // constructor(name:string,hobby:string){
    //     this.name=name;
    //     this.hobby=hobby;
    // }
    get psh():string{
        return this.name + this.hobby;
    }
    set psh(value){
        console.log(value);
        
    }
}
// let psn = new Persons("wqrwq","吃喝玩乐");
let psn = new Persons()
console.log(psn);
psn.psh = "好好吃饭睡觉"


// 抽象类
abstract class Parent{
    abstract run();
    abstract jump();
}
class Son extends Parent{
    run() {
        console.log("子类当中的");
        
    }
    jump() {
        console.log("子类中的跳");
        
    }
}
let Danny = new Son();
Danny.run();
Danny.jump()


















export {
    tom
}